﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ev_OneChain.Service
{
    public class sendHTTP
    {
        //
        static string strSMS = "http://front.chc.mobi/sms.php";

        static string strRegister = "http://front.chc.mobi/member/signup";

        public string sendSMS(string mobile) {

            //Random rd = new Random();
            //rd.//(生成1~10之间的随机数，不包括10)

            var strPost = "https://api.mysubmail.com/message/xsend.json";
            var vars = "{ 'code':'54321' }";
            vars = System.Web.HttpUtility.UrlEncode(vars, System.Text.Encoding.GetEncoding("GB2312"));
            var param = "appid=25536&to=" + mobile + "&project=i8Ozb3&signature=87ec46b26561bdb417b22ee69b321af7&vars=" + vars;
            //param = "{\"appid\":\"25536\",\"to\":\"" + mobile + "\",\"project\":\"i8Ozb3\",\"signature\":\"87ec46b26561bdb417b22ee69b321af7\",\"vars\":{\"code\":\"1234\"}}";
            var codeStatus = Tools.HttpClient.PostWebRequest(strPost, param);
            return "";
        }



        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public string sendSMSCode(string mobile)
        {
            string strcode = mobile + "!@#$%^7890";
            strcode = Tools.toolsMD5.GetMd5(strcode);
            //DA7823A58E19EB6C4527E2FF03A022A9
            string postUrl = strSMS + "?mobile=" + mobile + "&access_code=" + strcode;
            var codeStatus = Tools.HttpClient.PostWebRequest(postUrl, "");

            var strParam = "{'mobile':'" + mobile + "','access_code':'" + strcode + "'}";
           codeStatus = Tools.HttpClient.PostUrlJson(strSMS, strParam);

            return codeStatus;

        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public string sendRegister(string insPhone, string insPwd, string insPwdQ, string insYQR)
        {
            string postUrl = "mobile=" + insPhone + "&passwd=" + insPwd + "&passwd_repeat=" + insPwdQ + "&sharemobile=" + insYQR ;
            //var codeStatus = Tools.HttpClient.PostWebRequest(strRegister , postUrl);

            var codeStatus = Tools.HttpClient.RequestData(strRegister, postUrl);

            //var strParam = "{'mobile':'" + insPhone + "','passwd':'" + insPwd + "','passwd_repeat':'" + insPwdQ + "','sharemobile':'" + insYQR + "'}";
            //codeStatus = Tools.HttpClient.PostUrl(strRegister, strParam);
            return codeStatus;

        }



    }
}